//
//  JWTTests.m
//  CoreUser
//
//  Created by Demi on 18/04/2017.
//  Copyright © 2017 Azazie. All rights reserved.
//

#import <XCTest/XCTest.h>
#import <TXFire/TXFire.h>
#import <Base64/MF_Base64Additions.h>

@interface JWTTests : XCTestCase

@end

@implementation JWTTests

- (void)setUp {
    [super setUp];
    // Put setup code here. This method is called before the invocation of each test method in the class.
}

- (void)tearDown {
    // Put teardown code here. This method is called after the invocation of each test method in the class.
    [super tearDown];
}

- (void)testExample
{
    // This is an example of a functional test case.
    // Use XCTAssert and related functions to verify your tests produce the correct results.
    
    NSString *tokenString = @"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJhemF6aWUiLCJhdWQiOiJ1c2VycyIsImlhdCI6MTQ5MjUwNzA1OSwiZXhwIjoxNDkzMTExODU5LCJ1c2VyX2lkIjoiNWI4MzgyYzUwNGIifQ.zgAu6Qp_5-w4WS32vwrnVJ0RcOO6MIUv6EHa1dZUXWQ";
    
    NSArray *parts = [tokenString componentsSeparatedByString:@"."];
    
    XCTAssertTrue(parts.count >= 3);
    
    NSString *headerPart = parts[0];
    NSData *base64HeaderData = [[NSData alloc] initWithBase64EncodedString:headerPart options:1];
    NSDictionary *headerJSON = [NSJSONSerialization JSONObjectWithData:base64HeaderData options:0 error:NULL];
    TXLogVars(headerJSON);
    XCTAssertNotNil(headerJSON);
    
    NSString *payloadPart = parts[1];
    TXLogVars(payloadPart);
    
//    NSData *base64Data = [NSData dataWithBase64UrlEncodedString:payloadPart];
    NSData *base64Data = [[NSData alloc] initWithBase64EncodedString:payloadPart options:0];
//    NSData *base64Data = [[NSData alloc] initWithBase64EncodedString:[payloadPart tx_stringByDecodingURL] options:0];
//    NSData *base64Data = [[NSData alloc] initWithBase64EncodedString:[payloadPart tx_stringByEncodingURL] options:0];
    
    XCTAssertNotNil(base64Data);
    
    NSDictionary *payload = [NSJSONSerialization JSONObjectWithData:base64Data options:0 error:NULL];
    
    TXLogVars(payload);
    
    XCTAssertNotNil(payload);
    XCTAssertTrue([payload isKindOfClass:NSDictionary.class]);
}

- (void)testPerformanceExample {
    // This is an example of a performance test case.
    [self measureBlock:^{
        // Put the code you want to measure the time of here.
    }];
}

@end
